use Selenium::Remote::Driver;
use Selenium::Firefox::Profile;

my $profile = Selenium::Firefox::Profile->new('profile_dir' => 'D:/selenium/selenium');

$profile->set_preference('browser.download.folderList' => 2);
$profile->set_preference('browser.download.dir' => 'D:\selenium');
$profile->set_preference('browser.helperApps.neverAsk.saveToDisk' => 'text/xml');
 
my $driver = Selenium::Remote::Driver->new(browser_name => "firefox",
                                           firefox_profile => $profile);


$driver->get('https://vpn.dahama.com.cn/wangzhishibiande');
my $element = $driver->find_element_by_id('username');
$element->send_keys('dahama');

$element = $driver->find_element_by_id('password');
$element->send_keys('xxxxxxxxxxx');

$element = $driver->find_element_by_id('btnSubmit_6');
$element->click();



if ($driver->get_current_url() =~ /p=admin-confirm&id=/) {
my $continue_element = $driver->find_element_by_name('btnContinue');
$continue_element->click();
}

$element = $driver->find_element_by_link_text('Import/Export');
$element->click();

$element = $driver->find_element_by_link_text('XML Import/Export');
$element->click();

$element = $driver->find_element_by_id('arrowEndpoint');
$element->click();

my $option_element = $driver->find_element_by_id('optHCAll');
$option_element->click();

$element = $driver->find_element_by_id('arrowLocalUsers');
$element->click();

$option_element = $driver->find_element_by_id('optLocalUsersAll');
$option_element->click();

$option_element = $driver->find_element_by_id('action_6');
$option_element->click();

sleep(10);

$driver->quit();

$driver = Selenium::Remote::Driver->new(browser_name => "firefox",
                                        firefox_profile => $profile);

$driver->get('https://vpn.dahama.com.cn/wangzhishibiande');
my $element = $driver->find_element_by_id('username');
$element->send_keys('dahama');

$element = $driver->find_element_by_id('password');
$element->send_keys('xxxxxxxxxxx');

$element = $driver->find_element_by_id('btnSubmit_6');
$element->click();



if ($driver->get_current_url() =~ /p=admin-confirm&id=/) {
my $continue_element = $driver->find_element_by_name('btnContinue');
$continue_element->click();
}

$element = $driver->find_element_by_link_text('Import/Export');
$element->click();

$element = $driver->find_element_by_link_text('XML Import/Export');
$element->click();

$element = $driver->find_element_by_link_text('Import');
$element->click();

my $remote_fname = $driver->upload_file( 'ive-export.xml' );
$element = $driver->find_element_by_id( 'xml_roles_and_policies' );
$element->send_keys( $remote_fname );
   
$option_element = $driver->find_element_by_id('action_7');
$option_element->click();

do 
{
 sleep(2);
} while (! $driver->find_element_by_id('table_xml-errors_1'));

$driver->quit();
